| 1 |  |  | (function ($, app) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |     'use strict'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |     $.extend(app, { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |         PJAX_FLASH_CONTAINER: '.notification-container', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |         PJAX_FLASH: 'pjax-flashes', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |         PJAX_FLASH_SELECTOR: '[data-pjax-flashes]', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |         MESSAGE_SUCCESS: 0, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |         MESSAGE_ERROR: 1, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |         MESSAGE_WARNING: 2, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |         MESSAGE_NOTICE: 3, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |         message: function (text, status) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |             this.clearMessage(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |             if (!status) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |                 status = this.MESSAGE_SUCCESS; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |             var msgbox = $('<div></div>').appendTo(app.PJAX_FLASH_CONTAINER); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |             msgbox.addClass('alert'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |             msgbox.hide(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |             msgbox.text(text); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |             switch (status) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |                 case this.MESSAGE_SUCCESS : | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |                 case 'success' : | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |                     msgbox.addClass('alert-success'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |                     break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |                 case this.MESSAGE_NOTICE : | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |                 case 'notice' : | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |                     msgbox.addClass('alert-info'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |                     break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |                 case this.MESSAGE_WARNING : | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |                     msgbox.addClass('alert-warning'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |                     msgbox.html('<i class="icon-warning-sign"></i> ' + msgbox.text()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |                     break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |                 case this.MESSAGE_ERROR : | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |                 case 'error' : | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |                     msgbox.addClass('alert-danger'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |                     msgbox.html('<i class="icon-erroralt"></i> ' + msgbox.text()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |                     break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |             msgbox.data("time", new Date()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |             msgbox.fadeIn(500); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         }, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         clearMessage: function () { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |             $(app.PJAX_FLASH_CONTAINER + ' > div').each(function () { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |                 var time = $(this).data("time"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |                 if (!time || (new Date() - time >= 5 * 1000)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |                     $(this).fadeOut(1000, function () { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |                         $(this).html(""); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |                     }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |             }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     $(document) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         .on('pjax:send', app.clearMessage) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         .on('pjax:error', function (event, xhr, textStatus, error, options) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |             if ('abort' !== textStatus) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |                 app.message('Error', app.MESSAGE_ERROR); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         }) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         .on('pjax:beforeReplace', function (event, contents, options) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |             var tmp = $('<div></div>'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |             tmp.html(contents); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |             var flashes = $(app.PJAX_FLASH_SELECTOR, tmp); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |             if (flashes) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |                 var flashData = flashes.data(app.PJAX_FLASH); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |                 if (flashData) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |                     $(app.PJAX_FLASH_CONTAINER).html(flashData); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |                 flashes.removeData(app.PJAX_FLASH); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |                 flashes.removeAttr('data-' + app.PJAX_FLASH); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 79 |  |  |             } | 
            
                                                        
            
                                    
            
            
                | 80 |  |  |         }); | 
            
                                                        
            
                                    
            
            
                | 81 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 82 |  |  | })(jQuery, application); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                        
            
                                    
            
            
                | 83 |  |  |  |